package light.head.dao.el;

import java.util.List;

import light.head.enm.RESULT;
import light.head.framework.base.BaseDAO;
import light.head.model.el.ClassCourseTopicRelation;
import light.head.model.el.ClassCourseTopicRelationPK;

import org.springframework.stereotype.Service;

/**
 * 班级课程题目指定关系
 * @author yuleidian
 */
@Service
public class ClassCourseTopicRelationDAO extends BaseDAO<ClassCourseTopicRelation, ClassCourseTopicRelationPK>{
private final String hql_findByClcCode = "FROM ClassCourseTopicRelation cctr WHERE cctr.clc = ?";
	
	/**
	 * 根据班级code 查询信息
	 * @return
	 */
	public List<ClassCourseTopicRelation> findByClcCode(Integer code){
		if(code == null){
			 return null;
		}
		return find(hql_findByClcCode,code);
	}
	
	public List<ClassCourseTopicRelation> findByClcAndCc(Integer clc, Integer cc){
		String sql = "FROM ClassCourseTopicRelation cctr WHERE cctr.clc = ? AND cctr.cc = ?";
		return findI(sql, clc, cc);
	}
	public ClassCourseTopicRelation findByClcCcTc(Integer clc,Integer cc,Integer tc){
		String sql = "FROM ClassCourseTopicRelation cctr WHERE cctr.clc = ? AND cctr.cc = ? AND tc = ?";
		return (ClassCourseTopicRelation)get(sql,clc,cc,tc);
	}
	/**
	 * 更新
	 * @return
	 */
	public RESULT update(ClassCourseTopicRelation cctr){
		if(cctr == null ){
			return RESULT.ERROR;
		}
		
		ClassCourseTopicRelation old = findByClcCcTc(cctr.getClc(),cctr.getCc(),cctr.getTc());
		if(old != null){
			if(cctr.getPoints() != null && cctr.getPoints() != old.getPoints()){
				old.setPoints(cctr.getPoints());
			}
			return upd(old);
		}
		return RESULT.ERROR;
	}
}
